package com.itheima.homework.BankAccount_manager;

public class BankAccount {
    /**
     * 创建一个代表银行帐户的BankAccount类。
     * 它应该具有用于帐号、帐户持有人名称、余额的私有实例变量，以及用于帐户总数的静态变量。
     * 实现存入、提取和显示账户信息的方法。使用继承来创建SavingsAccount和CurrentAccount这样的子类。
     */

    static int accounts;

    private int id;
    private String name;
    private double money;

    public BankAccount() {
        accounts++;
    }

    public BankAccount(int id, String name, double money) {
        this.id = id;
        this.name = name;
        this.money = money;
    }

    public static int getAccounts() {
        return accounts;
    }

    public static void setAccounts(int accounts) {
        BankAccount.accounts = accounts;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public double getMoney() {
        return money;
    }

    public void setMoney(double money) {
        this.money = money;
    }

    // 实现存入、提取和显示账户信息的方法

    // 存入 返回余额
    public double saveMoney(double money) {
        if (money <= 0) {
            System.out.println("别闹！");
        } else {
            this.setMoney(this.getMoney() + money);
            System.out.println("成功存入 " + money + " 元");
        }

        return this.getMoney();
    }

    // 提取 返回余额
    public double drawMoney(double money) {
        if (money <= 0) {
            System.out.println("只能取钱");
        } else if (money > this.getMoney()) {
            System.out.println("取不了");
        } else {
            this.setMoney(this.getMoney() - money);
            System.out.println("成功取款: " + money + " 元");
        }
        return this.getMoney();
    }

    // 显示账户信息
    public void info() {
        System.out.println("客户 " + this.getName() + " 您好: 您当前账户: " + this.getId() + " 余额: " + this.getMoney());
    }
}
